package org.vectrics.recruiter.struts.admin.person;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionForm;

/**
 * @author pgoette
 * Formulario encargado de representar los datos de la universidad
 */
public class UniversityForm extends VectricsActionForm {

	private static final long serialVersionUID = -169145198864248689L;

	/**
	 * id de la universidad
	 */
	private String id;
	
	/**
	 * nombre de la universidad
	 */
	private String name;

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	protected ActionErrors doValidate(ActionMapping mapping, Request request) {
		ActionErrors errors = super.doValidate(mapping, request);
		
		// si presiono cancel salgo.
		if (this.wasButtonPressed(request, "cancel")) {
			return errors;
		}
		
		// si el name es nulo o vacio genero un error 
		if ((this.getName()==null)||(this.getName().trim().equals(""))) {
			errors.add("name", new ActionMessage("error.requiered.university.name"));
		}
		
		return errors;
	}

}
